<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends MY_Controller {

	
  public function __construct(){
    $this->need_login=true;
    parent::__construct();
  }
	public function index()
	{ 
   
		$this->load->helper('url');
		

		 $this->load->view('admin/index');
	}

	public function head(){
		$this->load->view('admin/head.html');
	}
	public function left(){
		$this->load->view('admin/left.html');
	}
	public function main(){

    		$this->load->helper('url');
    		$this->load->helper('func');
  	  	$this->load->database();
        if(isset($_COOKIE['mercode'])){
  	  	  $mercode =$_COOKIE['mercode'];
        }
  	  	if(!empty($_POST)){
  	  		$root_path= FCPATH.'uploads/';
  	  		$floder = $_POST['floder'];
  	  		$newname= $_POST['newname'];
  	  		$oldname = $_POST['oldname'];
  	  		$vid = $_POST['vid'];
  	  		$update = "UPDATE file_information SET filename= '$newname' WHERE vid=$vid"; 	  		
  	  		$query = $this->db->query($update);
  	  		$path = $root_path.$floder."/";//文件储存路径
  	  		$res = fileRename($path,$newname,$oldname);//重命名
  	  		if($query!=''&&$res==true){
  	  			echo json_encode(array('code'=>'0','msg'=>'修改成功'));
  	  			exit();
  	  		}else{
  	  			echo json_encode(array('code'=>'3001','msg'=>'修改失败'));
  	  			exit();
  	  		}
  	  	}
        if($mercode!=''){
          $sql = "SELECT filename,size,floder,modifytime,vid FROM file_information WHERE mercode=$mercode";
          $query = $this->db->query($sql);
          $rows = $query->result();
            $files["file"]=$rows;

         $count = "SELECT SUM(size) AS nums FROM file_information WHERE  mercode=$mercode";
         $query = $this->db->query($count);
         $row = $query->row();
         $total = getRealSize($row->nums);
         $files["totalSize"] =  $total;

        }
		 

  	  	//$sql="SELECT * FROM file_information WHERE mercode='602206'";
         
       

  	  	 $this->load->view('admin/main',$files);
  		
	}
	public function head2(){
		$this->load->view('admin/head2.html');
	}
	public function tab(){
		$this->load->view('admin/tab.html');
	}
	


}